declare -A hashmap

for file in brown/*[0-9]; do
	echo "Reading $file"
	sed 's_\([^ ]*\)/[^ ]*_\1_g' $file > t1.txt
	sed "s/'//g" t1.txt > t2.txt
	sed "s/\`//g" t2.txt > t3.txt
	sed "s/\[//g" t3.txt > t4.txt
	sed "s/\]//g" t4.txt > t5.txt
	sed "s/\\$//g" t5.txt > t6.txt
	#delete all ,
	sed "s/,//g" t6.txt > t7.txt
	#delete all .t
	sed "s/\.//g" t7.txt > t8.txt
	while read -r line; do
		line="$line"
		if [ ${#line} -gt 0 ]; then
			#echo $line 

			for word in $line; do
				if [ ${#word} -gt 0 ]; then
				        #echo ${word}
					if [ ${hashmap[${word}]+_} ]; then
						let hashmap[$word]=$((hashmap[${word}]+1))
					else
						let hashmap[$word]=1
					fi
				fi
			done
		fi
	done < "t8.txt"
	#break
done
loop=10
while(( $loop>0 ))
do
	topWord=""
	topFreq=0

	for i in "${!hashmap[@]}"; do
  	if [ $topFreq -lt ${hashmap[$i]} ]; then
        	topWord=$i
        	topFreq=${hashmap[$i]}
  	fi
	done
	echo "$topWord:${hashmap[$topWord]}"
	echo "$topWord:${hashmap[$topWord]}" >> answer1.txt
	hashmap[$topWord]=0
	let "loop--"
done
#delete all of the "print"
